﻿// <copyright file="Director.cs" company="City of Portland, BES-ASM">
// </copyright>
// <summary>Director class</summary>

namespace BESASM.EMGAATS.BusinessClasses
{
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;

  /// <summary>
  /// Manages where runoff from Area objects goes
  /// </summary>
  public class Director : Entity, IDirector
  {
    private IPoint geometry;
    private DirectorType directorType;
    private int areaSqFt;
    private IArea area;
    private INode toNode;

    /// <summary>
    /// Initializes a new instance of the <see cref="Director"/> class
    /// </summary>
    /// <param name="id">The ID of the Director</param>
    public Director(int id)
      : base(EntityType.Director, id)
    {
      this.directorType = DirectorType.Storm;
    }

    /// <summary>
    /// Gets or sets the point representing this director
    /// </summary>
    public IPoint Geometry
    {
      get
      {
        return this.geometry;
      }

      set
      {
        if (value != this.geometry)
        {
          this.geometry = value;
          this.NotifyPropertyChanged();
        }
      }
    }

    /// <summary>
    /// Gets or sets the amount of area to direct
    /// </summary>
    public int AreaSqFt
    {
      get
      {
        return this.areaSqFt;
      }

      set
      {
        if (value != this.areaSqFt)
        {
          this.areaSqFt = value;
          this.NotifyPropertyChanged();
        }
      }
    }

    /// <summary>
    /// Gets or sets the type of Director
    /// </summary>
    public DirectorType DirectorType
    {
      get
      {
        return this.directorType;
      }

      set
      {
        if (value != this.directorType)
        {
          this.directorType = value;
          this.NotifyPropertyChanged();
        }
      }
    }

    /// <summary>
    /// Gets or sets the Area this director takes runoff from
    /// </summary>
    public IArea Area
    {
      get
      {
        return this.area;
      }

      set
      {
        if (value != this.area)
        {
          this.area = value;
          this.NotifyPropertyChanged();
        }
      }
    }

    /// <summary>
    /// Gets or sets which Node the Director is leading to
    /// </summary>
    public INode ToNode
    {
      get
      {
        return this.toNode;
      }

      set
      {
        if (value != this.toNode)
        {
          this.toNode = value;
          this.NotifyPropertyChanged();
        }
      }
    }

    /// <summary>
    /// Creates a new entity that is a copy of the current instance.
    /// </summary>
    /// <returns>A new object that is a shallow copy of this instance.</returns>
    public override object Clone()
    {
      Director clone = new Director(this.Id);

      // Simple properties and references
      // DO NOT copy Network, clones must be added to a network
      clone.AreaSqFt = this.AreaSqFt;
      clone.DirectorType = this.DirectorType;
      clone.ToNode = this.ToNode;

      // Geometry (copy)
      if (this.Geometry != null)
      {
        clone.Geometry = this.Geometry.Clone() as IPoint;
      }

      this.CloneAuditProperties(clone);

      clone.SetModified(false);
      return clone;
    }

    /// <summary>
    /// Returns a string representation of this director
    /// </summary>
    /// <returns>A string representation of this director</returns>
    public override string ToString()
    {
      return string.Format("D{0}-N{1} (AreaSqFt: {2})", this.Id, this.ToNode == null ? 0 : this.ToNode.Id, this.AreaSqFt);
    }
  }
}
